package com.intelli4.pos.ui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;

public class MenuPanel extends JPanel {
	private static final long serialVersionUID = -3539305133255030463L;

	static class CategoryPanel extends JScrollPane {
		private static final long serialVersionUID = -2743846382100669422L;

		private JPanel rootPanel = new JPanel();

		private int buttonSize = 128;

		public CategoryPanel() {
			init();
		}

		protected void init() {
			addComponentListener(new ComponentAdapter() {

				@Override
				public void componentResized(ComponentEvent e) {
					super.componentResized(e);

					Dimension d = new Dimension(getViewport().getSize());
					d.width -= 52;
					d.height = rootPanel.getHeight();
					rootPanel.setPreferredSize(d);
				}
			});

			rootPanel.setLayout(new FlowLayout(FlowLayout.LEADING, 10, 10));

			JButton btn1 = new JButton("Combo1");
			btn1.setPreferredSize(new Dimension(buttonSize, buttonSize));
			rootPanel.add(btn1);

			JButton btn2 = new JButton("Combo2");
			btn2.setPreferredSize(new Dimension(buttonSize, buttonSize));
			rootPanel.add(btn2);

			JButton btn3 = new JButton("20 oz Pepsi");
			btn3.setPreferredSize(new Dimension(buttonSize, buttonSize));
			rootPanel.add(btn3);

			JButton btn4 = new JButton("Medium Fries");
			btn4.setPreferredSize(new Dimension(buttonSize, buttonSize));
			rootPanel.add(btn4);

			JButton btn5 = new JButton("Soft Taco");
			btn5.setPreferredSize(new Dimension(buttonSize, buttonSize));
			rootPanel.add(btn5);

			getViewport().add(rootPanel);
		}
	}

	public MenuPanel() {
		init();
	}

	protected void init() {
		setLayout(new BorderLayout());

		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.RIGHT);

		Font font = new Font(tabbedPane.getFont().getName(), Font.BOLD, 24);
		tabbedPane.setFont(font);
		tabbedPane.add("Popular", new CategoryPanel());
		tabbedPane.add("Tacos", new CategoryPanel());
		tabbedPane.add("Burritos", new CategoryPanel());
		tabbedPane.add("Value Menu", new CategoryPanel());
		tabbedPane.add("Combos", new CategoryPanel());
		tabbedPane.add("Specials", new CategoryPanel());
		tabbedPane.add("Drinks", new CategoryPanel());
		tabbedPane.add("Sides", new CategoryPanel());

		add(tabbedPane, BorderLayout.CENTER);
	}

	public static void main(String[] args) {
		JFrame frame = new JFrame(NumberPadPanel.class.getName());
		MenuPanel panel = new MenuPanel();
		frame.add(panel, BorderLayout.CENTER);
		frame.setSize(400, 300);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
	}
}
